import com.lijinjiang.beautyeye.BeautyEyeLNFHelper;

import javax.swing.*;
import java.awt.*;

/**
 * @ClassName Demo01
 * @Description TODO
 * @Author Li
 * @Date 2022/9/14 4:26
 * @ModifyDate 2022/9/14 4:26
 * @Version 1.0
 */
public class Demo01 {
    public static void main(String[] args) {
        try {
            BeautyEyeLNFHelper.frameBorderStyle = BeautyEyeLNFHelper.FrameBorderStyle.generalNoTranslucencyShadow;
            BeautyEyeLNFHelper.launchBeautyEyeLNF();
        } catch (Exception e) {
            e.printStackTrace();
        }
        JFrame frame = new JFrame();
        frame.setTitle("Demo01");
        frame.setSize(new Dimension(400, 300));
        JMenuBar menuBar = new JMenuBar(); // 创建一个菜单栏
        JMenu fileMenu = new JMenu("文件"); // 创建一级菜单
        JMenu editMenu = new JMenu("编辑"); // 创建一级菜单
        JMenu viewMenu = new JMenu("视图"); // 创建一级菜单
        JMenu helpMenu = new JMenu("帮助"); // 创建一级菜单

        // 文件菜单
        JMenuItem newMenuItem = new JMenuItem("新建"); // 创建一级子菜单
        JMenuItem openMenuItem = new JMenuItem("打开");
        JMenuItem exitMenuItem = new JMenuItem("退出");
        fileMenu.add(newMenuItem);
        fileMenu.add(openMenuItem);
        fileMenu.addSeparator();
        fileMenu.add(exitMenuItem);

        // 编辑菜单
        JMenuItem copyMenuItem = new JMenuItem("复制");
        JMenuItem pasteMenuItem = new JMenuItem("粘贴");
        editMenu.add(copyMenuItem);
        editMenu.add(pasteMenuItem);

        // 视图菜单
        JCheckBoxMenuItem checkBoxMenuItem01 = new JCheckBoxMenuItem("复选框子菜单01");
        JCheckBoxMenuItem checkBoxMenuItem02 = new JCheckBoxMenuItem("复选框子菜单02");
        JCheckBoxMenuItem checkBoxMenuItem03 = new JCheckBoxMenuItem("复选框子菜单03");
        JRadioButtonMenuItem radioButtonMenuItem01 = new JRadioButtonMenuItem("单选按钮子菜单01");
        JRadioButtonMenuItem radioButtonMenuItem02 = new JRadioButtonMenuItem("单选按钮子菜单02");
        JRadioButtonMenuItem radioButtonMenuItem03 = new JRadioButtonMenuItem("单选按钮子菜单03");
        ButtonGroup buttonGroup = new ButtonGroup(); // 单选按钮要生效，需要放到一个按钮组中
        buttonGroup.add(radioButtonMenuItem01);
        buttonGroup.add(radioButtonMenuItem02);
        buttonGroup.add(radioButtonMenuItem03);
        viewMenu.add(checkBoxMenuItem01);
        viewMenu.add(checkBoxMenuItem02);
        viewMenu.add(checkBoxMenuItem03);
        viewMenu.addSeparator();
        viewMenu.add(radioButtonMenuItem01);
        viewMenu.add(radioButtonMenuItem02);
        viewMenu.add(radioButtonMenuItem03);

        // 新建 子菜单添加监听器
        newMenuItem.addActionListener(e -> {
            System.out.println("点击新建按钮");
        });
        // 退出 子菜单添加监听器
        exitMenuItem.addActionListener(e -> {
            System.exit(0);
        });
        // 复选框子菜单01 添加监听
        checkBoxMenuItem01.addActionListener(e -> {
            System.out.println("复选框子菜单01是否被选中：" + checkBoxMenuItem01.isSelected());
        });
        // 单选按钮子菜单01 添加监听
        radioButtonMenuItem01.addActionListener(e -> {
            System.out.println("复选框子菜单01是否被选中：" + radioButtonMenuItem01.isSelected());
        });

        // 关于菜单
        JMenuItem aboutMenuItem = new JMenuItem("关于");
        helpMenu.add(aboutMenuItem);

        menuBar.add(fileMenu);
        menuBar.add(editMenu);
        menuBar.add(viewMenu);
        menuBar.add(helpMenu);

        frame.setJMenuBar(menuBar); // 设置菜单栏
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        frame.setLocationRelativeTo(null);
        frame.setVisible(true);
    }
}
